﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DSheet.Core;
using DSheet.Core.CommonData;
using DSheet.Core.Data;

namespace DExcelServiceApp
{
    public partial class DocTemplateList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _ctlHiddenEntityDefId.Value = Request.QueryString["id"];

                using (DBContext context = new DBContext())
                {
                    List<BDomain> domains = new CommonDataService().GetDomains(context);
                    _ctlListDomain.DataSource = domains;
                    _ctlListDomain.DataBind();

                    List<BOrg> orgs = new CommonDataService().GetOrgs(context);
                    _ctlListOrg.DataSource = orgs;
                    _ctlListOrg.DataBind();

                    List<BYear> years = new CommonDataService().GetYears(context);
                    _ctlListYear.DataSource = years;
                    _ctlListYear.DataBind();
                }
            }
        }

        protected void _ctlBtnPublish_Click(object sender, EventArgs e)
        {
            using (DBContext context = new DBContext())
            {
                DocDefService service = new DocDefService();
                Guid defid = new Guid(_ctlHiddenEntityDefId.Value);
                Guid bdid = new Guid(_ctlListDomain.SelectedValue);
                Guid orgid = new Guid(_ctlListOrg.SelectedValue);
                Guid yearid = new Guid(_ctlListYear.SelectedValue);

                DocDef def = DocDefService.GetDocDef(context, defid);
                service.Publish(context, yearid, bdid, orgid, def);
            }
        }
    }
}